home *** CD-ROM | disk | FTP | other *** search
- /**************************************************************************
- *
- * Copyright (c) 1992 Silicon Graphics, Inc.
- * All Rights Reserved
- *
- * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF SGI
- *
- * The copyright notice above does not evidence any actual of intended
- * publication of such source code, and is an unpublished work by Silicon
- * Graphics, Inc. This material contains CONFIDENTIAL INFORMATION that is
- * the property of Silicon Graphics, Inc. Any use, duplication or
- * disclosure not specifically authorized by Silicon Graphics is strictly
- * prohibited.
- *
- * RESTRICTED RIGHTS LEGEND:
- *
- * Use, duplication or disclosure by the Government is subject to
- * restrictions as set forth in subdivision (c)(1)(ii) of the Rights in
- * Technical Data and Computer Software clause at DFARS 52.227-7013,
- * and/or in similar or successor clauses in the FAR, DOD or NASA FAR
- * Supplement. Unpublished - rights reserved under the Copyright Laws of
- * the United States. Contractor is SILICON GRAPHICS, INC., 2011 N.
- * Shoreline Blvd., Mountain View, CA 94039-7311
- **************************************************************************
- *
- * File: status.c
- *
- * Description: Sample program that demonstrates the use of the standard
- * form of the libpod status read functions.
- *
- * Usage: status printer_name
- *
- **************************************************************************/
-
-
- #ident "$Revision: 1.4 $"
-
-
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <time.h>
- #include <pod.h>
-
-
- #define HANDLE_ERROR(pname) { \
- PDPerror(pname); \
- exit(1); \
- }
-
-
- void usage(char*);
- void disp_opstatus(int);
- void disp_status(PDStatusStruct*, PDMessageStruct*);
- void disp_colorspace(int);
- void disp_depth(int);
- void disp_format(int);
-
-
- int main(int argc, char **argv)
- {
- int opstatus;
- PDStatusStruct *status;
- PDMessageStruct *messages;
- time_t mod_time;
-
- /*
- * Get the printer name from command line
- */
- if (argc < 2) {
- usage(argv[0]);
- exit(1);
- }
-
- /*
- * Read and display only operational status
- */
- if (PDReadOpStatus(argv[1], &opstatus, &mod_time) < 0)
- HANDLE_ERROR(argv[0]);
- (void)printf("Current status summary - last modified %s\n",
- ctime(&mod_time));
- disp_opstatus(opstatus);
- (void)printf("\n");
-
- /*
- * Read and display the full status and message information
- */
- if (PDReadStatus(argv[1], &status, &messages, &mod_time) < 0)
- HANDLE_ERROR(argv[0]);
- (void)printf("Current complete status - last modified %s\n",
- ctime(&mod_time));
- disp_status(status, messages);
-
- return 0;
- }
-
-
- void usage(char *progname)
- {
- (void)fprintf(stderr, "Usage: %s printer_name\n", progname);
- }
-
-
- void disp_opstatus(int status)
- {
- (void)printf("\tOperational status: ");
- switch(status) {
- case PD_STATUS_IDLE:
- (void)printf("IDLE");
- break;
- case PD_STATUS_BUSY:
- (void)printf("BUSY");
- break;
- case PD_STATUS_FAULTED:
- (void)printf("FAULTED");
- break;
- case PD_STATUS_UNAVAILABLE:
- (void)printf("UNAVAILABLE");
- break;
- default:
- (void)printf("UNKNOWN");
- break;
- }
- (void)printf("\n");
- }
-
-
- void disp_status(PDStatusStruct *status, PDMessageStruct *messages)
- {
- register int i;
- char *options;
-
- disp_opstatus(status->operational_status);
- (void)printf("\tMedia type code: %d\n", status->media_type);
- (void)printf("\tNumber of colors code: 0x%08X\n",
- status->number_of_colors);
- (void)printf("\t\tNumber of colors: %d\n",
- PD_GET_NUMCOLORS(status->number_of_colors));
- disp_colorspace(PD_GET_COLORSPACE_CODE(status->number_of_colors));
- disp_depth(PD_GET_DEPTH_CODE(status->number_of_colors));
- disp_format(PD_GET_FORMAT_CODE(status->number_of_colors));
- (void)printf("\tMedia size code: 0x%08X\n", status->media_size);
- (void)printf("\tMedia size name: %s\n",
- PDGetNameBySizeCode(status->media_size));
- options = status->printer_options;
- (void)printf("\tInstalled options: %s\n",
- (options && *options != '\0') ? options: "None");
- (void)printf("\tMedia size validation mask: %d\n", status->validation_mask);
- (void)printf("\tNumber of messages: %d\n", status->error_count);
- for (i = 0; i < status->error_count; i++) {
- (void)printf("\n\t\tMessage %d code: 0x%08X\n", i+1,
- messages[i].message_code);
- (void)printf("\t\tMessage %d text: %s\n", i+1,
- messages[i].message_text);
- }
- }
-
-
- void disp_colorspace(int cspace)
- {
- (void)printf("\t\tColorspace: ");
- switch(cspace) {
- case PD_DATA_K:
- (void)printf("k\n");
- break;
- case PD_DATA_CMY:
- (void)printf("cmy\n");
- break;
- case PD_DATA_CMYK:
- (void)printf("cmyk\n");
- break;
- case PD_DATA_W:
- (void)printf("w\n");
- break;
- case PD_DATA_RGB:
- (void)printf("rgb\n");
- break;
- case PD_DATA_YMC:
- (void)printf("ymc\n");
- break;
- case PD_DATA_YMCK:
- (void)printf("ymck\n");
- break;
- case PD_DATA_KCMY:
- (void)printf("kcmy\n");
- break;
- default:
- (void)printf("0x%08X\n", cspace);
- break;
- }
- }
-
-
- void disp_depth(int depth)
- {
- (void)printf("\t\tDepth: ");
- switch(depth) {
- case PD_DATA_DEPTH1:
- (void)printf("1 bpp\n");
- break;
- case PD_DATA_DEPTH4:
- (void)printf("4 bpp\n");
- break;
- case PD_DATA_DEPTH8:
- (void)printf("8 bpp\n");
- break;
- default:
- (void)printf("0x%08X\n", depth);
- break;
- }
- }
-
-
- void disp_format(int format)
- {
- (void)printf("\t\tFormat: ");
- switch(format) {
- case PD_DATA_CHUNKY:
- (void)printf("chunky\n");
- break;
- case PD_DATA_BANDED:
- (void)printf("banded\n");
- break;
- case PD_DATA_PLANAR:
- (void)printf("planar\n");
- break;
- default:
- (void)printf("0x%08X\n", format);
- break;
- }
- }
-